package com.yifei.exception.filter;

import com.yifei.model.enums.ResultCode;
import com.yifei.utils.ResponseUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description: Spring Security访问异常处理器
 * @Author: yiFei
 * @date: 2023/9/24 19:53
 */
@Component
public class CustomAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResponseUtil.writeErrMsg(response, ResultCode.TOKEN_ACCESS_FORBIDDEN);
    }
}
